package gui;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.xml.ws.Dispatch;

import ch.randelshofer.quaqua.QuaquaLookAndFeel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.SpringLayout;
import javax.swing.JPanel;

public class Main {
	
	public static Main main = new Main();
	private JFrame frame;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					main.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 * 
	 * @throws UnsupportedLookAndFeelException
	 * @wbp.parser.entryPoint
	 */
	public Main() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 * 
	 * @throws UnsupportedLookAndFeelException
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		LookAndFeel x = new QuaquaLookAndFeel();
		try {
			UIManager.setLookAndFeel(x);
		} catch (UnsupportedLookAndFeelException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		JButton fixedPoint = new JButton("Fixed");
		fixedPoint.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				FixedSolver sc = new FixedSolver();
				sc.setVisible(true);
				setVisible(false);
				frame.dispose();
			}
		});
		SpringLayout springLayout = new SpringLayout();
		springLayout.putConstraint(SpringLayout.NORTH, fixedPoint, 56, SpringLayout.NORTH, frame.getContentPane());
		springLayout.putConstraint(SpringLayout.WEST, fixedPoint, 69, SpringLayout.WEST, frame.getContentPane());
		springLayout.putConstraint(SpringLayout.SOUTH, fixedPoint, 112, SpringLayout.NORTH, frame.getContentPane());
		springLayout.putConstraint(SpringLayout.EAST, fixedPoint, 183, SpringLayout.WEST, frame.getContentPane());
		frame.getContentPane().setLayout(springLayout);
		fixedPoint.setToolTipText("Find Fixed Point");
		frame.getContentPane().add(fixedPoint);

		JButton solve = new JButton("Solve");
		springLayout.putConstraint(SpringLayout.NORTH, solve, 56, SpringLayout.NORTH, frame.getContentPane());
		springLayout.putConstraint(SpringLayout.WEST, solve, 255, SpringLayout.WEST, frame.getContentPane());
		springLayout.putConstraint(SpringLayout.SOUTH, solve, 112, SpringLayout.NORTH, frame.getContentPane());
		springLayout.putConstraint(SpringLayout.EAST, solve, 369, SpringLayout.WEST, frame.getContentPane());
		solve.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SolverChooser.sa.setVisible(true);
			}
		});
		frame.getContentPane().add(solve);

		JButton interpolate = new JButton("Interpolate");
		springLayout.putConstraint(SpringLayout.NORTH, interpolate, 148, SpringLayout.NORTH, frame.getContentPane());
		springLayout.putConstraint(SpringLayout.WEST, interpolate, 69, SpringLayout.WEST, frame.getContentPane());
		springLayout.putConstraint(SpringLayout.SOUTH, interpolate, 204, SpringLayout.NORTH, frame.getContentPane());
		springLayout.putConstraint(SpringLayout.EAST, interpolate, 183, SpringLayout.WEST, frame.getContentPane());
		interpolate.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				InterpolatorChooser.p2v.setVisible(true);
			}
		});
		frame.getContentPane().add(interpolate);

		JButton exit = new JButton("Exit");
		springLayout.putConstraint(SpringLayout.NORTH, exit, 148, SpringLayout.NORTH, frame.getContentPane());
		springLayout.putConstraint(SpringLayout.WEST, exit, 255, SpringLayout.WEST, frame.getContentPane());
		springLayout.putConstraint(SpringLayout.SOUTH, exit, 204, SpringLayout.NORTH, frame.getContentPane());
		springLayout.putConstraint(SpringLayout.EAST, exit, 369, SpringLayout.WEST, frame.getContentPane());
		exit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		frame.getContentPane().add(exit);
		
		JPanel panel = new JPanel();
		springLayout.putConstraint(SpringLayout.NORTH, panel, 10, SpringLayout.NORTH, frame.getContentPane());
		springLayout.putConstraint(SpringLayout.WEST, panel, 25, SpringLayout.WEST, frame.getContentPane());
		springLayout.putConstraint(SpringLayout.SOUTH, panel, 26, SpringLayout.NORTH, fixedPoint);
		springLayout.putConstraint(SpringLayout.EAST, panel, 153, SpringLayout.WEST, frame.getContentPane());
		frame.getContentPane().add(panel);
	}

	public void setVisible(boolean b) {
		frame.setVisible(b);
		if(!b)
			frame.dispose();
	}
}
